package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.PurchaseCourseView;
import com.hyst.service.PurchaseCourseViewService;

/**
 * @Description:controller
 * @author：dy 
 *@Date：2018年08月31日
 */
@RestController
@RequestMapping("purchaseCourseViews")
@CrossOrigin(maxAge = 3600, origins = "*")
public class PurchaseCourseViewController {
	@Autowired
	private PurchaseCourseViewService purchaseCourseViewService;
	
	@GetMapping
	public ResultPage<PurchaseCourseView> list(PurchaseCourseView purchaseCourseView) {
		return ResultPage.success(purchaseCourseViewService.list(purchaseCourseView));
	}

	@GetMapping("id")
	public ResultBean<PurchaseCourseView> getById(PurchaseCourseView purchaseCourseView) {
		return ResultBean.success(purchaseCourseViewService.getById(purchaseCourseView));
	}

	@PostMapping
	public ResultBean<PurchaseCourseView> creat(final PurchaseCourseView purchaseCourseView) {
		return ResultBean.success(purchaseCourseViewService.insert(purchaseCourseView));
	}

	/**
	 * @Description: 根据主键查询
	 * @param uniqueid
	 * @return ResultBean<PurchaseCourseView>
	 */
	@GetMapping("{uniqueid}")
	public ResultBean<PurchaseCourseView> getByPriKey(@PathVariable("uniqueid") final String uniqueid) {
		return ResultBean.success(purchaseCourseViewService.getByPriKey(uniqueid));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param purchaseCourseView
	 * @return ResultBean<PurchaseCourseView>
	 */
	@PatchMapping("{uniqueid}")
	public ResultBean<PurchaseCourseView> update(final PurchaseCourseView purchaseCourseView) {
		return ResultBean.success(purchaseCourseViewService.update(purchaseCourseView));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param purchaseCourseView
	 * @return ResultBean<PurchaseCourseView>
	 */
	//@PutMapping("{uniqueid}")
	@PostMapping("{uniqueid}")
	public ResultBean<PurchaseCourseView> updatePatch(@PathVariable("uniqueid") final String uniqueid,
			final PurchaseCourseView purchaseCourseView) {
		return ResultBean.success(purchaseCourseViewService.updateSelective(purchaseCourseView));
	}

	/**
	 * @Description: 根据主键删除
	 * @param uniqueid
	 * @return ResultBean<PurchaseCourseView>
	 */
	@DeleteMapping("{uniqueid}")
	public ResultBean<PurchaseCourseView> delete(@PathVariable("uniqueid") final String uniqueid) {
		return ResultBean.success(purchaseCourseViewService.delete(uniqueid));
	}


}
